﻿using System;
using System.Collections;
using System.Data;
using System.Web.UI.WebControls;
using BLL;
using Utils;

namespace UI.ModEmployee
{
    public partial class EmpPasseBatchdAdd : System.Web.UI.Page
    {
        EmpPassedBiz empPassedBiz = new EmpPassedBiz();
        string account = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user"] != null)
            {
                User user = Session["user"] as User;
                account = user.Account;
            }
            else
            {
                JSUtility.Alert(this, "您没有登录!请先登录。");
                return;
            }
            if (!IsPostBack)
            {
                DataTable dt = empPassedBiz.GetLists();
                int r = dt.Rows.Count;

                if (r > 0)
                {
                    gvList.DataSource = dt;
                    gvList.DataBind();
                    lbNum.Text = "合计：" + r.ToString();
                    Panel1.Visible = true;
                }
              
            }
        }

        protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i <= gvList.Rows.Count - 1; i++)
            {
                CheckBox cbox = (CheckBox)gvList.Rows[i].FindControl("CheckBox1");
                if (CheckBox2.Checked == true)
                {
                    cbox.Checked = true;
                }
                else
                {
                    cbox.Checked = false;
                }
            }

        }
        protected void btnSet_Click(object sender, EventArgs e)
        {

            if (!AccountBiz.CheckRight(account, "EmpPasseBatchdAdd.aspx", RightChar.Add))
            {
                if (!AccountBiz.CheckRight(account, "EmpPassedList.aspx", RightChar.Add))
                {
                    JSUtility.Alert(this, "无权限！");
                    return;
                }
            }
            ArrayList empCodeArray = new ArrayList();

            foreach (GridViewRow gvr in gvList.Rows)
            {
                CheckBox ch = (CheckBox)gvr.FindControl("CheckBox1");
                if (ch.Checked == true)
                {

                    string strTmp = this.gvList.DataKeys[gvr.DataItemIndex].Value.ToString();
                    empCodeArray.Add(strTmp);
                }

            }
            if (empPassedBiz.ConfigSets(empCodeArray, account))
            { JSUtility.Alert(this, "设置成功"); }
            else
            { JSUtility.Alert(this, "设置失败"); }



        }
    }
}